Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
sparqljson-parse
Advanced tools
A utility package that allows you to parse SPARQL JSON results in a convenient RDFJS-based datastructure.
For example, the following SPARQL JSON result can be converted as follows:
In:
{
"head": {
"vars": [
"book"
]
},
"results": {
"bindings": [
{ "book": { "type": "uri", "value": "http://example.org/book/book1" } },
{ "book": { "type": "uri", "value": "http://example.org/book/book2" } },
{ "book": { "type": "uri", "value": "http://example.org/book/book3" } },
{ "book": { "type": "uri", "value": "http://example.org/book/book4" } },
{ "book": { "type": "uri", "value": "http://example.org/book/book5" } }
]
}
}
Out:
[
{ '?book': namedNode('http://example.org/book/book1') },
{ '?book': namedNode('http://example.org/book/book2') },
{ '?book': namedNode('http://example.org/book/book3') },
{ '?book': namedNode('http://example.org/book/book4') },
{ '?book': namedNode('http://example.org/book/book5') },
]
Where namedNode
is an RDFJS named node.
This library automatically converts all SPARQL JSON result values to their respective RDFJS type.
import {SparqlJsonParser} from "sparqljson-parse";
const sparqlJsonParser = new SparqlJsonParser();
Optionally, you can provide a settings object to the constructor with optional parameters:
const sparqlJsonParser = new SparqlJsonParser({
dataFactory: dataFactory, // A custom RDFJS datafactory
prefixVariableQuestionMark: true, // If variable names in the output should be prefixed with '?', default is false.
});
sparqlJsonParser.parseJsonBindings({ "book": { "type": "uri", "value": "http://example.org/book/book1" } })
// This will output { '?book': namedNode('http://example.org/book/book1') }
const sparqlJsonresponse = {
"head": {
"vars": [
"book"
]
},
"results": {
"bindings": [
{ "book": { "type": "uri", "value": "http://example.org/book/book1" } }
]
}
};
sparqlJsonParser.parseJsonResults(sparqlJsonresponse);
// This will output [ { '?book': namedNode('http://example.org/book/book1') } ]
const sparqlJsonresponse = {
"head": {},
"boolean": true
};
sparqlJsonParser.parseJsonBoolean(sparqlJsonresponse);
// This will output true
If you have many query results, then a streaming-based approach might be more efficient.
In this case, you can use the sparqlJsonParser.parseJsonResultsStream
method,
which takes a Node readable stream of SPARQL JSON results as a text stream,
and outputs a stream of parsed bindings.
Optionally, you can also retrieve the variables inside the head
as follows by listening to the variables
event:
sparqlJsonParser.parseJsonResultsStream(myStream)
.on('variables', (variables: RDF.Variable[]) => console.log(variables))
.on('data', (bindings: IBindings) => console.log(bindings));
sparqlJsonParser.parseJsonBooleanStream
also takes a stream as input,
but it returns a promise that resolves to a boolean.
This software is written by Ruben Taelman.
This code is released under the MIT license.
FAQs
Parses SPARQL JSON query results
The npm package sparqljson-parse receives a total of 1,251 weekly downloads. As such, sparqljson-parse popularity was classified as popular.
We found that sparqljson-parse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.